from selenium import webdriver
from time import sleep

driver = webdriver.Firefox()
driver.maximize_window()
driver.get('https://www.baidu.com/')
# 在当前打开的网页中设置cookie
driver.add_cookie({  # 字典格式
    'name': 'BDUSS',
    'value': 'jNVQWhRTm02WmdwRHNnQWRVV1JKbmFIWkc5UExBNm5laHB1QzY1SVRxNDFYdHBuRUFBQUFBJCQAAAAAAAAAAAEAAACHQjM~a2FybLPJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADXRsmc10bJnf'
})
# 重新发送请求(刷新浏览器即可)
sleep(3)
driver.refresh()
# 获取cookie
# cookie = driver.get_cookie('BDUSS')
# print(cookie)
# 获取所有的cookie
cookies = driver.get_cookies()
# print(cookies)
for item in cookies:
    print(item['name'])


sleep(3)
driver.quit()